package com.zhongwang.mms.module.overview.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.overview.model.ProjectStatusModel;
import com.zhongwang.mms.module.overview.service.ProjectStateService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 编辑项目状态
 * 查看 -> overview:project:view
 * 编辑 -> overview:project:edit
 *
 * @Author: China.sgl
 * @Date: 2020/4/10 10:19
 */
@SuppressWarnings("ALL")
@Slf4j
@Controller
@RequestMapping("/overview/state")
public class ProjectStateController extends BaseController {

    @Autowired
    private ProjectStateService projectStateService;

    /**
     * 生产状态编辑页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({"overview:project:view"})
    public String project() {
        return "overview/state/page";
    }

    /**
     * 列表数据
     *
     * @param projectStatusModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"overview:project:view"})
    public JsonResult list(ProjectStatusModel projectStatusModel) {
        startPage();
        List<ProjectStatusModel> list = projectStateService.findProject(projectStatusModel);
        return jsonResult(list);
    }

    /**
     * 查询项目状态
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/id")
    @RequiresPermissions({"overview:project:view"})
    public ProjectStatusModel id(Integer id) {
        return projectStateService.findProjectStateById(id);
    }

    /**
     * 修改项目状态
     *
     * @param projectStatusModel 项目状态
     * @return json
     */
    @ResponseBody
    @PostMapping("/edit")
    @RequiresPermissions({"overview:project:edit"})
    public JsonResult updateProject(ProjectStatusModel projectStatusModel) {
        return jsonResult(projectStateService.updateProjectStatus(projectStatusModel));
    }
    /**
     * 修改项目物控科状态
     *
     * @param projectStatusModel 项目状态
     * @return json
     */
    @ResponseBody
    @PostMapping("/saveMcData")
    @RequiresPermissions({"overview:project:edit"})
    public JsonResult saveMcData(ProjectStatusModel projectStatusModel) {
        return jsonResult(projectStateService.saveMcData(projectStatusModel));
    }
}
